package com.lagou.Server;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerInitClose {
    private ServerSocket ss;
    private Socket s;
    private ObjectInputStream ois;
    private ObjectOutputStream oos;

    public ObjectInputStream getOis() {
        return ois;
    }

    public ObjectOutputStream getOos() {
        return oos;
    }

    public void ServerInit() throws IOException {
        ss=new ServerSocket(6666);
        System.out.println("等待客户端的连接请求...");
        s=ss.accept();
        System.out.println("客户端连接成功!");
        ois=new ObjectInputStream(s.getInputStream());
        oos=new ObjectOutputStream(s.getOutputStream());
        System.out.println("服务器初始化成功!");
    }

    public void ServerClose() throws IOException {
        if(null!=oos) {
            oos.close();
        }
        if(null!=ois) {
            ois.close();
        }
        s.close();
        ss.close();
    }
}
